<script setup lang="ts">
import { ref } from 'vue'
import CameraTryOn from './components/CameraTryOn.vue'
// import { CameraTryOn } from '../lib/src/tryOn.js'
import type { PartialOptions } from './try-on/config'
const fdDisable = ref(false)
const sxDisable = ref(true)
const tryOn = ref<InstanceType<typeof CameraTryOn>>()
const options = ref<PartialOptions>({
  showFPS: true,
  enableContrast: false,
  three: { control: true },
})
const glassesUrl = ref('/reading-glasses/glasses.glb')
function swi() {
  if (tryOn.value?.TryOn.scene.contrast?.enable) {
    tryOn.value?.TryOn.scene.contrast?.disableClip()
  } else {
    tryOn.value?.TryOn.scene.contrast?.enableClip()
  }
}
function fd() {
  const { enlargeDisable, shrinkDisable } = tryOn.value!.TryOn.scene.enlargeCamera()
  sxDisable.value = shrinkDisable
  fdDisable.value = enlargeDisable
}
function sx() {
  const { shrinkDisable, enlargeDisable } = tryOn.value!.TryOn.scene.shrinkCamera()
  fdDisable.value = enlargeDisable
  sxDisable.value = shrinkDisable
}
</script>

<template>
  <div id="result">
    <CameraTryOn
      class="TryOn"
      ref="tryOn"
      :options="options"
      :glasses-url="glassesUrl"
    ></CameraTryOn>
    <div class="right-sec">
      <button :class="{ disable: fdDisable }" @click="fd">
        <img src="/img/加.png" />
      </button>
      <button :class="{ disable: sxDisable }" @click="sx">
        <img src="/img/减.png" />
      </button>
      <button @click="swi">
        <img src="/img/contrast.png" />
      </button>
    </div>
  </div>
  <!-- <button @click="glassesUrl = '/yellow-glasses/glasses.glb'">切换眼镜</button> -->
</template>
<style scoped lang="scss">
#result {
  display: flex;
  position: relative;
  width: 100%;
}
.TryOn {
  width: 100%;
}
.right-sec {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  right: 0;
  button {
    all: unset;
    width: 36px;
    height: 36px;
    box-sizing: border-box;
    background: transparent;
    display: block;
    padding: 4px;
    border-radius: 50%;
    overflow: hidden;
    margin: 8px 5px;
    background: #1c1e1f;
    img {
      width: 100%;
    }
  }
  .disable {
    background: #737873;
    cursor: not-allowed;
  }
}
</style>
<style>
#result {
  width: 640px;
}
* {
  margin: 0;
  padding: 0;
}
</style>
